package com.kilon.workfaq.rest;

import com.kilon.workfaq.entity.FilesmessagePo;
import com.kilon.workfaq.service.read.FilesmessageReadService;
import com.kilon.workfaq.service.write.FilesmessageWriteService;
import com.kilon.workfaq.util.ResultBean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Filesmessage)表控制层
 *
 * @author makejava
 * @since 2023-03-07 18:49:50
 */
@RestController
@RequestMapping("filesmessage")
public class FilesmessageRestService extends ResultBean {
    /**
     * 服务对象
     */
    @Resource
    private FilesmessageReadService filesmessageReadService;
    @Resource
    private FilesmessageWriteService filesmessageWriteService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @PostMapping("selectOne")
    public FilesmessagePo selectOne(Integer id) {
        return this.filesmessageReadService.queryById(id);
    }

    @PostMapping("queryAll")
    public List<FilesmessagePo> selectAll(@RequestBody FilesmessagePo filesmessagePo) {
        if ("0".equals(filesmessagePo.getBy1())) {
            filesmessagePo.setBy1(null);
        }
        return this.filesmessageReadService.queryAll(filesmessagePo);
    }

    /**
     * 新增项目
     *
     * @return
     */
    @PostMapping("addFilesmessage")
    public void addFilesmessage(FilesmessagePo filesmessagePo) {
        //这里添加自定义条件
        this.filesmessageWriteService.insert(filesmessagePo);
    }

    /**
     * 更新项目
     *
     * @return
     */
    @PostMapping("updateProject")
    public void updateFilesmessage(FilesmessagePo filesmessagePo) {
        //这里添加自定义条件
        if (this.filesmessageWriteService.update(filesmessagePo)) {
            //setResultData("更新成功");
        } else {
            //setErrorMsg("更新出错");
        }
    }

    /**
     * 删除项目
     *
     * @return
     */
    @PostMapping("dropFilesmessage")
    public void dropFilesmessage(FilesmessagePo filesmessagePo) {
        if (this.filesmessageWriteService.deleteById(filesmessagePo)) {
            //setResultData("删除成功");
        } else {
            //setErrorMsg("删除出错");
        }
    }
}
